package com.example.common.exception;

import com.example.common.constant.BizCodeEnum;

import java.util.Objects;

/**
 * <p>
 *
 * </p>
 *
 * @author zyred
 * @since v 0.1
 **/
public abstract class Assert extends org.springframework.util.Assert {

    /** false 抛异常 **/
    public static void isTrue (boolean b, String msg) {
        if (!b) {
            throw new RRException(msg);
        }
    }
    public static void isTrue (boolean b, BizCodeEnum e) {
        if (!b) {
            throw new RRException(e.getMsg());
        }
    }

    /** 是否是正数 > 0 **/
    public static void isPositive (int n, String e) {
        if (n <= 0) {
            throw new RRException(e);
        }
    }

    public static void isPositive (int n, BizCodeEnum e) {
        if (n <= 0) {
            throw new RRException(e.getMsg());
        }
    }

    /** 是否是负数数 < 0 **/
    public static void isMinus (int n, String e) {
        if (n > 0) {
            throw new RRException(e);
        }
    }

    public static void isMinus (int n, BizCodeEnum e) {
        if (n > 0) {
            throw new RRException(e.getMsg());
        }
    }

    /** 判断对象是否为null **/
    public static void isBlank(Object obj, String e) {
        if (Objects.isNull(obj)) {
            throw new RRException(e);
        }
    }
    public static void isBlank(Object obj, BizCodeEnum e) {
        if (Objects.isNull(obj)) {
            throw new RRException(e.getMsg());
        }
    }
}
